package particles;

class Engine
{
	public var model : EngineModel;

	public function new(maxCount : Int)
	{
		model = new EngineModel();
		model.maxCount = maxCount; 
	}

	public function update()
	{
		if (model.particles.length < model.maxCount)
		{
			for(i in 0 ... 10)
			{
				var particle = new Particle2();
				particle.reset(model);
				model.particles.push(particle);
			}
		}
		
		for (particle in model.particles)
		{		
			particle.update(model);
			
			if (particle.x < 0 || particle.y < 0 || particle.x > model.width * 2 || particle.y > model.height * 2
				|| particle.age > particle.ageDead)
				particle.reset(model);
		}
	}
}
